<template>
  <div class="playList">
    <div class="playlist-top">
      <div class="left">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-bofang1"></use>
        </svg>
        <div class="text">
          <div class="title">播放全部</div>
          <div class="num">(共{{ playlists.tracks.length }}首)</div>
        </div>
      </div>
      <div class="btn">
        +收藏（{{ changeValue(playlists.subscribedCount) }}）
      </div>
    </div>
    <div class="list">
      <div class="playItem" v-for="(item, i) in playlists.tracks" :key="i">
        <div class="left">
          <div class="index">{{ i + 1 }}</div>
          <div class="content">
            <div class="title">{{ item.name }}</div>
            <div class="author">
              <div
                class="tags"
                v-for="(tag, index) in randomSort(playlists.tags)"
                :key="index"
              >
                <div
                  v-show="index < getRandomNum(playlists.tags.length)"
                  class="tag"
                >
                  {{ tag }}
                </div>
              </div>
              <div class="explain">{{ item.al.name }}</div>
            </div>
          </div>
        </div>
        <div class="right">
          <svg class="icon bofang" aria-hidden="true" @click="getplayer(i)">
            <use xlink:href="#icon-caozuo-bofang"></use>
          </svg>
          <svg class="icon gengduo" aria-hidden="true">
            <use xlink:href="#icon-icmore"></use>
          </svg>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions, mapMutations, mapState } from "vuex";
import { changeValue, getRandomNum, randomSort } from "@/util/index.js";
import emitter from "@/util/bus";
export default {
  props: ["playlists"],
  computed:{
    ...mapState(['playlist','playCurrentIndex','timer'])
  },
  methods: {
    ...mapMutations(["setPlayIndex"]),
    ...mapActions(['reqLyric']),
    getplayer(i){
      this.setPlayIndex(i)
      console.log(66666,this.playlist)
      this.reqLyric(this.playlists.tracks[this.playCurrentIndex])
      clearInterval(this.timer)
      emitter.emit('updatePlay',{
        playFlag:false
      })
    }
  },
  setup() {
    return {
      changeValue,
      getRandomNum,
      randomSort,
    };
  },
};
</script>

<style lang="less" scoped>
.playList {
  width: 7.5rem;
  padding: 0 0.4rem;
  background-color: #fff;
  border-radius: 0.3rem 0.3rem 0 0;
  margin-top: 0.8rem;
  .playlist-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 0.8rem;
    .left {
      display: flex;
      align-items: center;
      .icon {
        width: 0.4rem;
        height: 0.4rem;
        margin-right: 0.1rem;
      }
      .text {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        .title {
          font-size: 0.4rem;
          margin-right: 0.2rem;
        }
        .num {
          color: #ccc;
          font-size: 0.3rem;
        }
      }
    }
    .btn {
      font-size: 0.2rem;
      color: #fff;
      background-color: #ff4d39;
      height: 0.6rem;
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 0.1rem;
      border-radius: 0.4rem;
    }
  }
  .list {
    .playItem {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px 0;
      .left {
        display: flex;
        .index {
          width: 0.8rem;
          height: 0.8rem;
          display: flex;
          justify-content: center;
          align-items: center;
          color: #ccc;
        }
        .content {
          width: 5rem;
          .title {
            font-size: 0.35rem;
            padding: 5px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
          .author {
            font-size: 0.15rem;
            display: flex;
            align-items: center;
            justify-content: flex-start;
            .tags {
              float: left;
              .tag {
                // width: 100%;
                display: block;
                white-space: nowrap;
                color: rgba(255, 77, 87);
                background-color: rgba(255, 77, 57, 0.3);
                margin-right: 5px;
                border: 1px solid rgba(255, 77, 97);
                border-radius: 4px;
              }
            }
            .explain {
              float: left;
              // height: 0.5rem;
              word-break: normal;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
          }
        }
      }
      .right {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .bofang {
          width: 0.4rem;
          height: 0.4rem;
          margin-right: 5px;
        }
        .gengduo {
          width: 0.4rem;
          height: 0.4rem;
        }
      }
    }
  }
}
</style>
